package bancosys.tec.persist.entities.domain;

import java.util.SortedSet;
import java.util.TreeSet;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;

import jmine.tec.persist.annotation.Alias;

import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;
import org.hibernate.annotations.Filter;
import org.hibernate.annotations.Filters;
import org.hibernate.annotations.Parameter;
import org.hibernate.annotations.Sort;
import org.hibernate.annotations.SortType;
import org.hibernate.annotations.Type;

import bancosys.tec.component.Documentation;
import bancosys.tec.persist.bussobj.AuthPersistableBusinessObject;

@Entity
@Table(name = "PAPEL")
@Alias("PAPEL")
@Documentation("PAPEL")
@Filters({ @Filter(name = "authFilter", condition = "auth = :auth") })
public class Papel extends AuthPersistableBusinessObject {

    private Long id;

    private SortedSet<FluxoPagamento> fluxos = new TreeSet<FluxoPagamento>();

    private Something something = Something.SOME;

    /**
     * @return the id
     */
    @Id
    @GeneratedValue
    @Column(name = "COD_PAP")
    public Long getId() {
        return this.id;
    }

    /**
     * @param id the id to set
     */
    public void setId(Long id) {
        this.id = id;
    }

    /**
     * @return the fluxos
     */
    @OneToMany(mappedBy = "papel")
    @Cascade({ CascadeType.ALL, CascadeType.DELETE_ORPHAN })
    @Sort(type = SortType.NATURAL)
    public SortedSet<FluxoPagamento> getFluxos() {
        return this.fluxos;
    }

    /**
     * @param fluxos the fluxos to set
     */
    public void setFluxos(SortedSet<FluxoPagamento> fluxos) {
        this.fluxos = fluxos;
    }

    private boolean dirty;

    @Override
    @Transient
    public boolean isDirty() {
        return this.dirty;
    }

    @Override
    public void setDirty(boolean flag) {
        this.dirty = flag;
    }

    /**
     * @return the something
     */
    @Column(name = "SOMETHING")
    @Type(type = "bancosys.tec.persist.hibernate.type.StaticIdEnumType", parameters = { @Parameter(name = "enumClass", value = "bancosys.tec.persist.entities.domain.Something") })
    public Something getSomething() {
        return this.something;
    }

    /**
     * @param something the something to set
     */
    public void setSomething(Something something) {
        this.something = something;
    }

}
